package com.xyebank.ledger.service.sjdzadd.dataProvider.credit;

import com.xyebank.ledger.service.common.DataProvider;
import com.xyebank.ledger.util.DateUtil;
import com.xyebank.ledger.vo.deal.ZADDSjdCashCreditVo;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Component
public class ZADDSjdCreditDataProvider implements DataProvider<ZADDSjdCashCreditVo> {

	@Autowired
	private ZADDSjdCashCreditMapper ZaddSjdCashCreditMapper;

	@Override
	public List<ZADDSjdCashCreditVo> get(Integer fromIdx, Integer tarNum) {
		List<ZADDSjdCashCredit> result = ZaddSjdCashCreditMapper.selectByPaging(fromIdx, tarNum);
		List<ZADDSjdCashCreditVo> list = convert2Vo(result);
		return list;
	}

	@Override
	public List<ZADDSjdCashCreditVo> get(Date dateStart, Date dateEnd, Integer fromIdx, Integer tarNum) {

		List<ZADDSjdCashCredit> result = ZaddSjdCashCreditMapper.selectByPeriod(DateUtil.getFormatDate(dateStart), DateUtil.getFormatDate(dateEnd), fromIdx, tarNum);
		List<ZADDSjdCashCreditVo> list = convert2Vo(result);
		return list;
	}

	@Override
	public Integer count(Date timeStart, Date timeEnd) {
		Integer num = ZaddSjdCashCreditMapper.selectPeriodCount(DateUtil.getFormatDate(timeStart), DateUtil.getFormatDate(timeEnd));
		return num;
	}

	private List<ZADDSjdCashCreditVo> convert2Vo(List<ZADDSjdCashCredit> result) {
		List<ZADDSjdCashCreditVo> list = new ArrayList<ZADDSjdCashCreditVo>();
		for (int i = 0; i < result.size(); i++) {
			ZADDSjdCashCreditVo vo = new ZADDSjdCashCreditVo();
			BeanUtils.copyProperties(result.get(i), vo);
			list.add(vo);
		}
		return list;
	}

}
